package com.ibeeking.found.msg.rest.controller.v1;

import com.ibeeking.found.msg.rest.service.IWxMpGroupMessageCountService;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


//预留回调
@Deprecated
@RestController
@RequestMapping(value = "/mp/messagecount/v1")
public class WxMpRequestMessageController {

    @Resource
    private IWxMpGroupMessageCountService wxMpGroupMessageCountServiceImpl;

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "预留公众号群发任务后回调接口")
    @GetMapping(value = "/mp_return/{appId}")
    public String groupMessageCallback(@PathVariable("appId") String appId, HttpServletRequest request) {
        MultipartHttpServletRequest file = (MultipartHttpServletRequest )request;
        Iterator<String> iterator = file.getFileNames();
        List<String> fileNames = new ArrayList<>();
        while (iterator.hasNext()){
            fileNames.add(iterator.next());
        }
        return wxMpGroupMessageCountServiceImpl.groupMessageCallback(appId,file.getFile(fileNames.get(0)));
    }
}

